package main

import "fmt"

func main() {
	n := 2
	c := make(chan int)
	done := make(chan bool)

	go func() {
		for i := 0; i < 1000; i++ {
			c <- i
		}
		close(c)
	}()

	go func() {
		for v := range c {
			fmt.Println("func 1 from chan c:", v)
		}
		done <- true
	}()

	go func() {
		for v := range c {
			fmt.Println("func 2 from chan c:", v)
		}
		done <- true
	}()

	for i := 0; i < n; i++ {
		go func() {
			for v := range c {
				fmt.Printf("func x-%v from chan c: %v\n", i, v)
			}
			done <- true
		}()
	}

	<-done
	<-done

	for i := 0; i < n; i++ {
		<-done
	}
	fmt.Println("执行完毕。。。。")
}
